package com.example.gzysmartcity.ui.fragment.me;

import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.CleanUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.example.gzysmartcity.databinding.FragmentSettingBinding;
import com.example.gzysmartcity.databinding.PopuCleanBinding;
import com.example.gzysmartcity.ui.base.BaseFragment;

import org.jetbrains.annotations.NotNull;

public class SettingFragment extends BaseFragment<FragmentSettingBinding> {
    @Override
    protected FragmentSettingBinding viewBinding() {
        return FragmentSettingBinding.inflate(getLayoutInflater(), baseBinding.getRoot(), true);
    }

    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        b.tvCommityjian.setOnClickListener(v -> jump(CommitFragment.class, null, null));//跳转fragment
        b.tvCleanhuanc.setOnClickListener(v -> {
            PopuCleanBinding popuCleanBinding = PopuCleanBinding.inflate(LayoutInflater.from(getContext()));
            //获取当前屏幕宽度跟高度
            Resources resources = requireContext().getResources();
            DisplayMetrics dm = resources.getDisplayMetrics();
            int width = dm.widthPixels;
            int height = dm.heightPixels;
            //x = 1440,y = 2960
            //对话框风格窗口
            PopupWindow popupWindow = new PopupWindow(popuCleanBinding.getRoot());
            popupWindow.setWidth(width);
            popupWindow.setHeight(height);
//          popupWindow.showAsDropDown(v);//以下拉方式弹出
            popupWindow.setFocusable(true);
            //将对话框显示在指定位置
            popupWindow.showAtLocation(popuCleanBinding.getRoot(), Gravity.CENTER, 0, 0);
            popuCleanBinding.tvCleanNo.setOnClickListener(v1 -> popupWindow.dismiss());
            popuCleanBinding.tvCleanYes.setOnClickListener(v1 -> {
                CleanUtils.cleanInternalCache();
                ToastUtils.showShort("缓存已清除");
                popupWindow.dismiss();
            });
        });
    }

    @Override
    protected String setTitle() {
        return "设置";
    }

    @Override
    protected boolean showBack() {
        return true;
    }

    @Override
    protected Boolean showBottom() {
        return null;
    }
}
